package com.mz.mattress.admin.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mz.mattress.api.entity.CardMerchant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Set;

@Mapper
public interface CardMerchantMapper extends BaseMapper<CardMerchant> {

    @Select("select * from mz_card_merchant where card_id=#{cardId}")
    List<CardMerchant> selectByCardId(Integer cardId);

    @Select("select merchant_id from mz_card_merchant where card_id=#{cardId}")
    List<Integer> selectMerchantIdByCardId(Integer cardId);

//    default int deleteByMerchantIds(Set<String> merchantIds) {
//        if (merchantIds == null || merchantIds.isEmpty()) {
//            return 0;
//        }
//        QueryWrapper<CardMerchant> wrapper = new QueryWrapper<>();
//        wrapper.in("merchant_id", merchantIds);
//        return this.delete(wrapper);
//    }

    int deleteByMerchantIds(@Param("cardId") Integer cardId, @Param("merchantIds") Set<Integer> merchantIds);

    @Update("UPDATE mz_card_merchant a,mz_merchant b set a.merchant_name=b.name where a.merchant_id=b.id and ISNULL(a.merchant_name)")
    void updateMerchantNameIsNull();

}
